<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs v-model="activeName">
          <el-tab-pane label="登录账户设置">

            <!-- 放置表单 -->
            <el-form label-width="120px" style="margin-left: 120px; margin-top:30px">
              <el-form-item label="姓名:">
                <el-input v-model="userDetail.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:">
                <el-input v-model="userDetail.password" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="updateUserInfo">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <UserInfo :user-detail="userDetail" />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <JobInfo />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getUserDetailById, saveUserDetailById } from '@/api/employees'
import JobInfo from '@/views/employees/components/JobInfo.vue'
import UserInfo from '@/views/employees/components/UserInfo.vue'
import Cookie from 'js-cookie'
export default {
  components: {
    JobInfo,
    UserInfo
  },
  data() {
    return {
      userDetail: {},
      activeName: Cookie.get('activeName') || '0'
    }
  },
  watch: {
    activeName(val) {
      Cookie.set('activeName', val)
    }
  },
  created() {
    this.getUserDetail()
  },
  methods: {
    async getUserDetail() {
      const res = await getUserDetailById(this.$route.params.id)
      this.userDetail = { ...res, password: '' }
    },
    async updateUserInfo() {
      await saveUserDetailById(this.userDetail)
      this.$message.success('修改用户信息成功')
    }
  }
}
</script>

<style>

</style>
